<header class="d-flex bg-body flex-column flex-md-row text-nowrap closed z-3">
  <h1 class="d-flex m-0 align-items-center fw-semibold">
    <a href="<%= root_path %>" class="icon-link gap-1 me-auto text-body-emphasis text-decoration-none geolink">
      <%= image_tag "osm_logo.svg", :alt => t("layouts.logo.alt_text"), :size => 30 %>
      <%= t "layouts.project_name.h1" %>
    </a>
    <%= render "layouts/select_language_button", :extra_classes => ["border-secondary border-opacity-10 d-md-none"] %>
    <a href="#" id="menu-icon" class="d-md-none">
      <%= inline_svg_tag "menu-icon.svg", :size => "30px" %>
    </a>
  </h1>
  <nav class='primary'>
    <%= content_for :header %>
    <div id="edit_tab" class="btn-group w-100">
      <%= link_to t("layouts.edit"),
                  edit_path,
                  :class => "btn btn-outline-primary geolink editlink",
                  :id => "editanchor",
                  :data => { :editor => preferred_editor } %>
      <button class='btn btn-outline-primary dropdown-toggle dropdown-toggle-split flex-grow-0' type='button' data-bs-toggle='dropdown'></button>
      <ul class='dropdown-menu'>
        <% Editors::RECOMMENDED_EDITORS.each do |editor| %>
          <li>
            <%= link_to t("layouts.edit_with", :editor => t("editor.#{editor}.description")),
                        edit_path(:editor => editor),
                        :data => { :editor => editor },
                        :class => "geolink editlink dropdown-item" %>
          </li>
        <% end %>
      </ul>
    </div>
  </nav>
  <nav class='secondary d-flex flex-column flex-md-row gap-2 flex-grow-1 align-items-center'>
    <ul id='secondary-nav-menu' class='nav flex-grow-1 justify-content-center justify-content-md-start' data-turbo-permanent>
      <% if Settings.status != "database_offline" && can?(:index, Issue) %>
        <li class="nav-item">
          <%= link_to issues_path(:status => "open"), :class => header_nav_link_class(issues_path) do %>
            <%= t("layouts.issues") %>
            <%= open_issues_count %>
          <% end -%>
        </li>
      <% end %>
      <li class="nav-item">
        <%= link_to t("layouts.history"), history_path, :class => header_nav_link_class(history_path) %>
      </li>
      <li class="nav-item">
        <%= link_to t("layouts.export"), export_path, :class => header_nav_link_class(export_path) %>
      </li>
      <li class="nav-item">
        <%= link_to t("layouts.gps_traces"), traces_path, :class => header_nav_link_class(traces_path) %>
      </li>
      <li class="nav-item">
        <%= link_to t("layouts.user_diaries"), diary_entries_path, :class => header_nav_link_class(diary_entries_path) %>
      </li>
      <li class="nav-item">
        <%= link_to t("layouts.communities"), communities_path, :class => header_nav_link_class(communities_path) %>
      </li>
      <li class="nav-item">
        <%= link_to t("layouts.copyright"), copyright_path, :class => header_nav_link_class(copyright_path) %>
      </li>
      <li class="nav-item">
        <%= link_to t("layouts.help"), help_path, :class => header_nav_link_class(help_path) %>
      </li>
      <li class="nav-item">
        <%= link_to t("layouts.about"), about_path, :class => header_nav_link_class(about_path) %>
      </li>
      <li id="compact-secondary-nav" class="dropdown nav-item ms-auto">
        <button class="dropdown-toggle nav-link btn btn-outline-secondary border-0 bg-body text-secondary" type="button" data-bs-toggle="dropdown"><%= t "layouts.more" %></button>
        <ul class="dropdown-menu">
        </ul>
      </li>
    </ul>

    <%= render "layouts/select_language_button", :extra_classes => ["d-none d-md-block", { "border-secondary-subtle" => current_user&.id }] %>
    <% if current_user && current_user.id %>
      <div class='d-inline-flex dropdown user-menu logged-in'>
        <button class='d-flex gap-1 align-items-center justify-content-center dropdown-toggle btn btn-outline-secondary border-secondary-subtle bg-body text-secondary px-2 py-1 flex-grow-1 mw-100' type='button' data-bs-toggle='dropdown'>
          <%= user_thumbnail_tiny(current_user, :class => "user_thumbnail_tiny rounded-1 bg-body") %>
          <% if current_user.new_messages.size > 0 %>
            <span class="badge count-number position-static m-1"><%= current_user.new_messages.size %></span>
          <% end %>
          <span class='username align-middle text-truncate' dir='auto'>
            <%= current_user.display_name_was %>
          </span>
        </button>
        <div class='dropdown-menu dropdown-menu-end'>
          <%= link_to t("users.show.my_dashboard"), dashboard_path, :class => "dropdown-item" %>
          <%= link_to messages_inbox_path, :class => "dropdown-item" do %>
            <%= t("users.show.my messages") %>
            <span class='badge count-number'><%= number_with_delimiter(current_user.new_messages.size) %></span>
          <% end %>
          <%= link_to t("users.show.my profile"), current_user, :class => "dropdown-item" %>
          <%= link_to t("users.show.my_account"), account_path, :class => "dropdown-item" %>
          <%= link_to t("users.show.my_preferences"), basic_preferences_path, :class => "dropdown-item" %>
          <div class="dropdown-divider"></div>
          <% if current_user.home_location? %>
            <%= link_to t("layouts.home"), account_home_path, :class => "dropdown-item" %>
          <% end %>
          <%= link_to t("layouts.logout"), logout_path(:referer => request.fullpath), :method => "post", :class => "geolink dropdown-item" %>
        </div>
      </div>
    <% else %>
      <div class="d-inline-flex btn-group login-menu" role="">
        <%= link_to t("layouts.log_in"), login_path(:referer => request.fullpath), :class => "geolink btn btn-outline-secondary" %>
        <%= link_to t("layouts.sign_up"), new_user_path, :class => "btn btn-outline-secondary" %>
      </div>
    <% end %>
  </nav>
</header>

<div class="modal fade" id="select_language_dialog" tabindex="-1" aria-labelledby="select_language_dialog_label" aria-hidden="true">
  <div class="modal-dialog modal-lg modal-dialog-scrollable">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="select_language_dialog_label"><%= t ".select_language" %></h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="<%= t "javascripts.close" %>"></button>
      </div>
      <div class="modal-body px-1">
        <turbo-frame id="select_language_list" src="<%= languages_pane_path %>?source=<%= ERB::Util.url_encode(request.fullpath) %>" loading="lazy">
          <div class="text-center py-3">
            <div class="spinner-border text-secondary" role="status">
              <span class="visually-hidden"><%= t ".loading" %></span>
            </div>
          </div>
        </turbo-frame>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="osm_alert_modal" tabindex="-1" aria-labelledby="osm_alert_title" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="osm_alert_title"></h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="<%= t "javascripts.close" %>"></button>
      </div>
      <div class="modal-body" id="osm_alert_message">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" data-bs-dismiss="modal"><%= t "javascripts.close" %></button>
      </div>
    </div>
  </div>
</div>
